<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/in.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>个人信息</title>
    <link rel="stylesheet" href="${staticPage}/css/weui.css"/>
    <link rel="stylesheet" href="${staticPage}/css/myInfo.css"/>
    <!--<link rel="stylesheet" href="css/example.css"/>-->
</head>
<script type="text/javascript">
	var isChange=false;    //是否更改信息
 	var isChangeTel=false;    //是否更换手机号
 	var isGetCode=false;   //是否获取验证码
//  	var oldTel=${current_user.tel}; //保存旧的手机号 
 	
	var countdown=60; 
	
	function settime(val) { 
		if (countdown == 0) { 
			val.removeAttr("disabled");   
			val.css("background-color","#02c69e")
			val.val("获取"); 
			countdown = 60; 
			return false;
		} else { 
			val.attr("disabled", "disabled"); 
			val.css("background-color","#adaead")
			val.val(countdown + "秒"); 
			countdown--; 
		} 
		setTimeout(function() { 
		settime(val) 
		},1000) 
	} 
 	function showToast(){
		 $('#toast').show();
        setTimeout(function () {
            $('#toast').hide();
            window.location.reload();
        }, 2000);
	}
 	//获取个人信息
	function getUserInfo(){
		$.getJSON("${ctx}/user_getUserInfo.json",function(json){
			if(json.success){
				$("input[name='realname']").val(json.name);
				$("input[name='birth']").val(json.birth);
				$("select[name='dot']").val(json.dot);
				$("input[name='tel']").val(json.tel);
			}
			else{
				alert(json.msg);
			}
				
		})	
 	}
	
	$(function(){
		//获取个人信息
		getUserInfo();
		//添加网点内容
		/* $("select[name='dot']").val("${current_user.dot}"); */
		
		$("#modifyButton").click(function(){
			isChange=true;
			$("input[name='realname']").removeAttr("disabled");
			$("input[name='birth']").removeAttr("disabled");
			$("input[name='tel']").removeAttr("disabled");
			
			$("#changeTel").css("display","")			
		});
		
// 		$("#changeTel").click(function(){
// 			isChangeTel=true;
// 			$("input[name='tel']").removeAttr("disabled");
// 			$("input[name='tel']").val("");
// 			$("#validateCode").css("display","");
// 		});
		
		$("#saveButton").click(function(){
			
			var realname=$("input[name='realname']").val();
			var tel=$("input[name='tel']").val();
			var birth=$("input[name='birth']").val();
// 			var code=$("input[name='code']").val();
// 			var sessionId=$("input[name='sessionId']").val();
			if(isChange){

					if(realname==""&&tel==""&&birth==""){
						 if(birth==""){
								alert("生日不能为空！");
							}
							else if(realname==""){
								alert("姓名不能为空！");
							}
							else if(tel==""){
								alert("更换手机号不能为空！");
							}

					}
					else{
							$.getJSON("${ctx}/user_modifyInfo.json",
									{name:realname,birth:birth,tel:tel},
							function(json){
								if(json.success){
									showToast();
								}
								else{
									alert(json.msg);
									}
							})
					}
				}
			
						 
			
		});
		//获取验证码
// 		$("#getCode").click(function(){
// 			isGetCode=true;
// 			if(oldTel==$("input[name='tel']").val()){
// 				alert("新手机号不能与之前的手机号相同！");
// 			}
// 			else{
// 				$.getJSON("${ctx}/user_sendMessage.json",
// 						{tel:$("#resggister_form  input[name='tel']").val()},
// 				function(json){
// 					if(json.success){
// 						alert("短信验证码发送成功！");
// 						settime($("#getCode"));
// 						$("input[name='sessionId']").val(json.sessionId);
// 						/* $("#wxUserForm input[name='code']").val(json.code); */				
// 					}
// 					else{
// 						alert(json.msg);
// 						}
// 				})
// 			}
// 		})
			
	})

</script>
<body>

        <!--注册表单-->
        <div class="weui_cells weui_cells_form" id="resggister_form">
        
        <input  type="hidden" name="sessionId"  id="sessionIdInput"/>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">姓名</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text"   name="realname" disabled="disabled" placeholder="未填写"/>
            </div>
            <div class="weui_cell_ft">
            </div>
        </div>
        
      
		

        <div class="weui_cell">
            <div class="weui_cell_hd"><label for="" class="weui_label">生日</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="date" value="" name="birth" disabled="disabled" placeholder="未填写" />
            </div>
        </div>

		 <div class="weui_cell">
            <div class="weui_cell_hd"><label for="" class="weui_label">网点</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                 <select class="weui_select" name="dot"  disabled="disabled">
                    <option value="" >请选择网点</option>
                    <option value="401">金牛支行营业室（沙湾路）</option>
                    <option value="402">成都花园支行（青羊大道）</option>
                    <option value="403">荷花池支行（金牛万达旁） </option>
                    <option value="404">外西支行（花牌坊北街） </option>
                    <option value="405">天回支行（天回镇上街）</option>
                    <option value="406">高笋塘支行（二环路北三段）</option>
                    <option value="407">西郊支行（十二桥路）</option>
                    <option value="408">洞子口支行（洞子口）</option>
                    <option value="409">洞子口支行（洞子口）</option>
                    <option value="410">蜀鑫支行（蜀鑫路）</option>
                    <option value="411">蜀西支行（蜀西路）</option>
                    <option value="412">五福支行（蓉北商贸大道）</option>
                    <option value="413">茶店子支行（茶店子东街）</option>
                    <option value="414">国际商贸城支行（国际商贸城）</option>
                    <option value="415">光华逸家分理处（万家湾光华逸家小区）</option>
                    <option value="416">大湾分理处（军区总医院内）</option>
                    <option value="417">蜀汉路支行（蜀蓉路）</option>
                    <option value="418">星辰支行（九里堤星辰路）</option>

                </select>
                <%-- <input class="weui_input" type="text" value="${current_user.tel}" name="dot"disabled="disabled"/> --%>
            </div>
        </div>

        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">手机号</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text"  name="tel"disabled="disabled" placeholder="待绑定"/>   <%-- ${current_user.tel} --%>
            </div>
			<!-- <div class="weui_cell_ft">
                <button id="getCodeButton">获取</button>
                <div class="weui_btn_area">
                    <a class="weui_btn     weui_btn_primary" href="javascript:" id="changeTel"  style="display:none">更换</a>
                </div>
            </div> -->
            
        </div>
        
        
        
        
        



      <!--   <div class="weui_cell"  style="display:none" id="validateCode">
            <div class="weui_cell_hd"><label class="weui_label">验证码</label></div>

            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="number" pattern="[0-9]*" name="code" placeholder="请输入验证码" />
            </div>

            <div class="weui_cell_ft">
                <button id="getCodeButton">获取</button>
                <div class="weui_btn_area">
                    <input class="weui_btn     weui_btn_primary"  id="getCode" type="button" value="获取">
                </div>
            </div>
        </div>-->
        </div> 

        <div class="weui_btn_area submitButton">
            <a class="weui_btn weui_btn_primary"  id="modifyButton">修改</a>
        </div>
        <div class="weui_btn_area cancleButton">
            <a class="weui_btn weui_btn_primary" id="saveButton">保存</a>
        </div>
        
        <div id="toast" style="display: none;">
            <div class="weui_mask_transparent"></div>
            <div class="weui_toast">
                <i class="weui_icon_toast"></i>
                <p class="weui_toast_content">修改成功！</p>
            </div>
        </div>
        
        
        	<div class="weui_cells weui_cells_access" id="infoUrl">
          <a class="weui_cell" id="info">
              <div class="weui_cell_bd weui_cell_primary">
                  <p>个人信息</p>
              </div>
              <div class="weui_cell_ft">撒地方
              </div>
          </a>
      </div>
        
</body>
</html>